<?php

    namespace App\Http\Controllers\V1_bak;

    use App\Dictionary\ErrorCode;
    use App\Http\Controllers\Controller;
    use App\Models\V1_bak\Cart;
    use Dingo\Api\Routing\Helpers;
    use Illuminate\Http\Request;

    class CartController extends Controller
    {
        use Helpers;

        /**
         * 获取购物车列表
         * @param Request $request
         * author: walker
         * Date: 2019/10/23
         * Time: 16:12
         */
        public function getCartList(Request $request)
        {

            session_id('sess_test');
            session_start();

            $name = session('name');
            print_r($name);die();
            $userId = $request->input('user_id');
            if (empty($userId)){
                ajaxReturn(4001, ErrorCode::$common[4001]);
            }
            $model    = new Cart();
            $cartList = $model->getCartList($userId);
            $data = [];
            $data['list']=$cartList;
            $data['count']=$model->countCart($userId);
            ajaxReturn(200, ErrorCode::$common[200], $data);
        }

        /**
         * 购物车统计
         * @param Request $request
         * author: walker
         * Date: 2019/10/23
         * Time: 16:23
         */
        public function countCart(Request $request)
        {
            $userId = $request->input('user_id');
            if(empty($userId)){
               ajaxReturn(4001, ErrorCode::$common[4001]);
            }
            $model = new Cart();
            $count = $model->countCart($userId);
            ajaxReturn(200, ErrorCode::$common[200], ['count' =>$count?:0]);
        }
    }
